package com.jerei.test;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties;

/**
 * Created by sunfeihu on 2016/12/14.
 */
public class SayHelloCommand extends HystrixCommand<String> {
    private final String _name;

    public SayHelloCommand(String name) {
        super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("HelloServiceGroup")).andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(5000)));
        _name = new String(name);

    }

    @Override
    protected String run() throws Exception {
        Thread.sleep(1000);
        return String.format("Hello %s!", _name);
    }

    @Override
    protected String getFallback() {
        return String.format("[FallBack]Hello %s!", _name);
    }
}
